import logging
import sys


logging.basicConfig(format='%(message)s', level=logging.INFO, encoding='utf-8')
user_code="1"
taskId='./arc_log.txt'


def logprint(msg,taskId='arc_log.txt',succ=False,noshow=False):
    if succ:
        msg=f'Execution succeeded: {msg}'
    if noshow:
        msg=msg.split('Execution succeeded: ')[1]
    logging.info(msg)
    with open(taskId, 'a+', encoding='utf-8') as f:
        f.write(f'{msg}' + '\n')


def customTask(serial, private_key, taskname, datafile, amount, delay,IP,twtoken,dctoken,email,aicapAPI):
    infoList=str([serial, private_key, taskname, datafile, amount, delay,IP,twtoken,dctoken,email,aicapAPI])
    logprint(infoList)
    logprint('成功执行此函数',succ=True)



if __name__ == "__main__":
    functions = {
        "customTask": customTask,
    }
    args = sys.argv
    function_name = args[1]

    if function_name in functions:
        try:
            res = functions[function_name](*args[2:])
            logprint(res, taskId)
        except Exception as e:
            logprint(f'error info: {e}', taskId)
    else:
        logprint("Invalid function name", taskId)